/*
 * Copyright (c) 2010 Vadim Zhukov <persgray@gmail.com>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */


#ifndef OW_COMMON_H
#define OW_COMMON_H

/*
 * Put simple, used almost everywhere definitions here.
 * No dependency on other project's header files allowed here, and the list of
 * external dependencies should be minimal.
 */

#include "../config.h"


enum { MAXLINE		= 1024 };	/* Maximum line length */
enum { MAXPEERADDRLEN	= 104  };	/* Max length of IPv[46]/local address*/
#define PEER_PORT		"707"	/* XXX: At least, unused on OpenBSD */
#define FILTER_PORT		"708"	/* XXX: At least, unused on OpenBSD */

#ifndef max
#	define max(a, b)	((a) >= (b) ? (a) : (b))
#endif

#ifndef min
#	define min(a, b)	((a) < (b) ? (a) : (b))
#endif

#ifndef nitems
#	define nitems(x)	(sizeof((x)) / sizeof((x)[0]))
#endif

#define DPRINTF(n, msg...)	do {					\
					int dpsverrno = errno;		\
					if (n <= debug)			\
						warn(msg);		\
					errno = dpsverrno;		\
				} while(0)

#define DPRINTFX(n, msg...)	do {					\
					int dpsverrno = errno;		\
					if (n <= debug)			\
						warnx(msg);		\
					errno = dpsverrno;		\
				} while(0)

#define fatal(msg...)		err(EXIT_FAILURE, msg)
#define fatalx(msg...)		errx(EXIT_FAILURE, msg)

extern int	debug;


#endif /* OW_COMMON_H */
